<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="ISO-8859-1"%>
<%@ page import = "quiz.Result" %>
<%@ page import = "quiz.Achievement" %>
<%@ page import = "quiz.Quiz" %>
<%@ page import = "quiz.Question" %>
<%@ page import = "quiz.QuizResponse" %>
<%@ page import = "java.util.ArrayList" %>
<jsp:include page="templates/header.jsp" flush="true">
	<jsp:param value = "Congratulations | Quizzard" name = "title" />
</jsp:include>
<jsp:include page="templates/title_bar.jsp" flush = "true">
	<jsp:param value = "You're done!" name = "title" />
</jsp:include>
<div id = "content">
<div class = "center">
<%
	Quiz q = (Quiz)request.getAttribute("quiz");
	int totalScore = (Integer)request.getAttribute("runningScore");
	ArrayList<QuizResponse> answers = (ArrayList<QuizResponse>)request.getAttribute("answers");
	
	ArrayList<Achievement> earnedAchievements = (ArrayList<Achievement>)request.getAttribute("achievementEarned");
	
	String time = (String)request.getAttribute("time");
	
	if (earnedAchievements != null && earnedAchievements.size() > 0) {
		out.print("<div id = \"success\">Congratulations! You earned: <ul>");
		for (Achievement a: earnedAchievements) {
			out.println("<li>"+Achievement.getAchievementName(a)+"</li>");
		}
		out.println("</ul></div>");
	}
%>

<div class = "section_title bottom_border">Congratulations! You just completed "<%= q.getName() %>"</div>
<p>Your score is <%= totalScore %> out of <%= q.getTotalPossibleScore() %></p>
<p>Completed in <%= time %></p>
<%
	//if (a != null) {
%>
<!--  <div class = "section_title" class = "bottom_border"></div>
You earned -->
<%
	//}
%>
<div class = "section_title bottom_border">Your Answers</div>
<div>
<%
	for(QuizResponse r: answers) {
		out.println("<div style = \"padding-top: 6px; padding-bottom: 6px\"><div class = \"question\">");
		if (r.getQuestion().getType() == Question.PICTURE) out.println("<img class = \"result_image\" src = \""+r.getQuestion().getContent()+"\" />");
		else out.println(r.getQuestion().getContent());
		out.println("</div>");
		if (r.isCorrect()) out.println("<div class = \"green\">Your answer: "+r.getContent()+"</div></div>");
		else out.println("<div class = \"red\">Your answer: "+r.getContent()+"</div></div>");
	}
%>
</div>
<a href = "SendMessage?quizID=<%= q.getID() %>"><span class = "btn">Challenge</span></a>
</div>
</div>
<jsp:include page="templates/footer.jsp" flush="true" />